package com.controller;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.DiscusskaoyanziliaoEntity;
import com.entity.view.DiscusskaoyanziliaoView;
import com.service.DiscusskaoyanziliaoService;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * 赵润波 2023-5.25
 * 考研资料评论表
 * 后端接口
 */
@RestController
@RequestMapping("/discusskaoyanziliao")
public class DiscusskaoyanziliaoController {
    @Autowired
    private DiscusskaoyanziliaoService discusskaoyanziliaoService;


    


    /**
     * 后端列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, DiscusskaoyanziliaoEntity discusskaoyanziliao,
                  HttpServletRequest request){
        EntityWrapper<DiscusskaoyanziliaoEntity> ew = new EntityWrapper<DiscusskaoyanziliaoEntity>();

		PageUtils page = discusskaoyanziliaoService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusskaoyanziliao), params), params));

        return R.ok().put("data", page);
    }
    
    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, DiscusskaoyanziliaoEntity discusskaoyanziliao,
                  HttpServletRequest request){
        EntityWrapper<DiscusskaoyanziliaoEntity> ew = new EntityWrapper<DiscusskaoyanziliaoEntity>();

		PageUtils page = discusskaoyanziliaoService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusskaoyanziliao), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list(DiscusskaoyanziliaoEntity discusskaoyanziliao){
       	EntityWrapper<DiscusskaoyanziliaoEntity> ew = new EntityWrapper<DiscusskaoyanziliaoEntity>();
      	ew.allEq(MPUtil.allEQMapPre( discusskaoyanziliao, "discusskaoyanziliao"));
        return R.ok().put("data", discusskaoyanziliaoService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(DiscusskaoyanziliaoEntity discusskaoyanziliao){
        EntityWrapper< DiscusskaoyanziliaoEntity> ew = new EntityWrapper< DiscusskaoyanziliaoEntity>();
 		ew.allEq(MPUtil.allEQMapPre( discusskaoyanziliao, "discusskaoyanziliao"));
		DiscusskaoyanziliaoView discusskaoyanziliaoView =  discusskaoyanziliaoService.selectView(ew);
		return R.ok("查询考研资料评论表成功").put("data", discusskaoyanziliaoView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        DiscusskaoyanziliaoEntity discusskaoyanziliao = discusskaoyanziliaoService.selectById(id);
        return R.ok().put("data", discusskaoyanziliao);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        DiscusskaoyanziliaoEntity discusskaoyanziliao = discusskaoyanziliaoService.selectById(id);
        return R.ok().put("data", discusskaoyanziliao);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DiscusskaoyanziliaoEntity discusskaoyanziliao, HttpServletRequest request){
    	discusskaoyanziliao.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
    	//ValidatorUtils.validateEntity(discusskaoyanziliao);
        discusskaoyanziliaoService.insert(discusskaoyanziliao);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody DiscusskaoyanziliaoEntity discusskaoyanziliao, HttpServletRequest request){
    	discusskaoyanziliao.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
    	//ValidatorUtils.validateEntity(discusskaoyanziliao);
        discusskaoyanziliaoService.insert(discusskaoyanziliao);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    public R update(@RequestBody DiscusskaoyanziliaoEntity discusskaoyanziliao, HttpServletRequest request){
        //ValidatorUtils.validateEntity(discusskaoyanziliao);
        discusskaoyanziliaoService.updateById(discusskaoyanziliao);//全部更新
        return R.ok();
    }


    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        discusskaoyanziliaoService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
    
	









}
